/*工单号*/
function html_wordOrder(entityList){ 
	var infoWordOrder = $("#infoWordOrder");
	$.each(entityList, function(i,item){
		var optiontop= "<option value='";
		var optionbody = "'>";
		var optionfoot ="</option> ";
		var option = optiontop+item.id+optionbody+item.infoWordOrder+optionfoot;
		infoWordOrder.append( option );
	});
}
/*单位*/
var html_Companies="<div class='cell-item'> " + 
	               "<div class='cell-left'>单位:</div>" +
	               "<div class='cell-right' id='divinfoCompanies'>" +
	               "<input id='infoForDepart' name='infoForDepart' style='display: none;' type='text' class='cell-input' placeholder='请输入单位编码' autocomplete='off' />"+
	               "<input id='infoForDepart1' name='infoForDepart' disabled='disabled' type='text' class='cell-input' placeholder='请输入单位编码' autocomplete='off''/></div>" +
	               "</div>";
/*派发时间*/
var html_infoCreateDate="<div class='cell-item'> " + 
						"<div class='cell-left'>派发时间:</div>" +
						"<div class='cell-right'>" +
						"<input id='infoCreateDate' name='infoCreateDate' disabled='disabled'  class='cell-input' placeholder='' autocomplete='off' />" +
						"</div>";

/*派发人员*/
var html_infoCreateName="<div class='cell-item'> " + 
						"<div class='cell-left'>派发人员:</div>" +
						"<div class='cell-right'>" +
						"<input id='infoCreateName' name='infoCreateName' disabled='disabled' type='text' class='cell-input' placeholder='' autocomplete='off' />" +
						"</div>";

/*故障发生地*/
var html_infoPlace="<div class='cell-item'> " + 
					"<div class='cell-left'>故障发生地:</div>" +
					"<div class='cell-right'>" +
					"<input id='infoPlace' name='infoPlace' disabled='disabled' type='text' class='cell-input' placeholder='' autocomplete='off' />" +
					"</div>";
/*故障原因*/
var html_Melreason= "<div class='cell-item'> " + 
					"<div class='cell-left'>故障原因:</div>" +
					"<div class='cell-right'><textarea id='infoReason' name='infoReason' type='text' class='cell-input' placeholder='请输入故障原因' autocomplete='off' datatype='*'></textarea></div>" +
					"</div>";
/*故障变电站*/
var html_Substation="<div class='cell-item'> " + 
					"<div class='cell-left'>故障变电站:</div>" +
					"<div class='cell-right' id='divinfoSubstation'><input id='infoSubstation' name='infoSubstation' type='text' class='cell-input' placeholder='请输入变电站' autocomplete='off' datetype='*'/></div>" +
					"</div>";
/*线路*/
var html_Lineinfo = "<div class='cell-item'> " + 
					"<div class='cell-left'>故障线路:</div>" +
					"<div class='cell-right' id='divinfoLinecode'><input id='infoLinecode' name='infoLinecode' type='text' class='cell-input' placeholder='请输入所在线路' autocomplete='off' datatype='*'/></div>" +
					"</div>";
/*台区*/
var html_Region  =  "<div class='cell-item'> " + 
					"<div class='cell-left'>故障台区:</div>" +
					"<div class='cell-right'><input id='infoRegion' name='infoRegion' type='text' class='cell-input' placeholder='请输入所处台区' autocomplete='off' datatype='*'/></div>" +
					"</div>";
/*处理结果*/
var html_Dispose_status="<div class='cell-item'> " +
						"<div class='cell-left'>处理结果：</div> "+
						"<label class='cell-right cell-arrow'> "+
						"<select id='infoDisposeStatus' name='infoDisposeStatus' class='cell-select'> "+
						"<option value='0'>未处理</option> "+
						"<option value='1'>已处理未恢复供电</option> "+
						"<option value='2'>已处理已恢复供电</option> "+ 
						"<option value='3'>特殊原因，无法处理</option> "+
						"</select></label></div>";
/*用户反馈*/
var html_Client_feedback=   "<div class='cell-item'> " +
							"<div class='cell-left'>用户反馈：</div> " +
							"<label class='cell-right cell-arrow'> " +
							"<select id='infoClinetFeedback' name='infoClinetFeedback' class='cell-select'> " +
							"<option value='0'>已回访，满意</option>" + 
							"<option value='1'>已回访，不满意</option> " +
							"<option value='2'>未回访</option> " +
							"<option value='3'>无法回访</option></select></label></div>";

/*故障类型*/
var html_InfoMelfunctionType=	"<div class='cell-item' style='display:none'> " + 
								"<div class='cell-left'>故障类型：</div>" +
								"<div class='cell-right'><input id='infoMelfunctionType' name='infoMelfunctionType' type='text' class='cell-input' value='"
var html_InfoMelfunctionType2= 	"' autocomplete='off'/></div></div>";

/*故障处理人员*/
var html_infoUpdateName  =  "<div class='cell-item'> " + 
							"<div class='cell-left'>故障处理人员:</div>" +
							"<div class='cell-right'><input id='infoUpdateName' name='infoUpdateName' type='text' disabled='disabled' class='cell-input' placeholder='' autocomplete='off' datatype='*'/></div>" +
							"</div>";


$(function(){
	var value = extract();//得出故障编码
	$.ajax({
		cache:false,
		type: 'post', // 提交方式 get/post
		async:false,
   		url: "infomelController.do?codeDataGrid", // 需要提交的 url
   		data:{'value':value},
   		dataType:"json",
       	success: function(json){ // data 保存提交后返回的数据，一般为 json 数据
       		if(json.success){
       			var entityList = json.obj;
       			html_wordOrder(entityList);
       		}else{
       			alert(json.msg);
       			window.location.href="infomelController.do?toMelfunction";
       		}
       	},
       	error :function(){
       	
       	}	
    });
})
function ajax1(wordNum,table,value){
	$.ajax({
		cache:false,
		type: 'post', // 提交方式 get/post
   		url: "infomelController.do?iDDataGrid", // 需要提交的 url
   		data:{'wordOrder':wordNum},
   		dataType:"json",
   		async:false,
       	success: function(json){ // data 保存提交后返回的数据，一般为 json 数据
       		if(json.success&&json.obj!=null){
       			var entity = json.obj;
       			selectHTML(table,value,entity);//加载页面
       			$("#id").attr('value',entity.id);//ID
       			var departName = fordepart(entity.infoForDepart);
       			var date = getMyDate(entity.infoCreateDate);
       			$("#infoForDepart").attr("value",entity.infoForDepart);//部门id
       			$("#infoForDepart1").attr("value",departName);//部门名称
       			$("#infoCreateDate").attr("value",date);//派单时间
       			$("#infoCreateName").attr("value",entity.infoCreateName);//派单人员
       			$("#infoPlace").attr("value",entity.infoPlace);//故障发生地
       		}
       	},
       	error : function(){
       		
       	}
	})
}
function extract(){
	var name , value;
	var str=location.href; //取得整个地址栏
	var num=str.indexOf("?")
	str=str.substr(num+1); //取得所有参数   stringvar.substr(start [, length ]
	var arr = new Array(); //定义一数组 
	arr=str.split("&"); //各个参数放到数组里
	for(var i=0;i < arr.length;i++){
		num=arr[i].indexOf("=");
	    if(num>0){
			name=arr[i].substring(0,num);
	        value=arr[i].substr(num+1);
	        this[name]=value;
	    }
	}
	return value;
}
function selectHTML(table,value){
	if(value=="GYGZ"){
		table.append(html_Companies); //部门
		table.append(html_infoCreateDate);//派发时间
		table.append(html_infoCreateName);//派发人员
		table.append( html_infoPlace);//故障发生地
		table.append(html_Substation);//故障变电站
		table.append(html_Lineinfo); //故障线路
		table.append(html_Region); //故障台区
		table.append(html_Melreason); //故障原因
		table.append(html_Dispose_status); //故障处理结果
		table.append(html_Client_feedback) //用户反馈结果
		table.append( html_InfoMelfunctionType + value + html_InfoMelfunctionType2);//故障类型
	}else if(value=="DYGZ"){
		table.append(html_Companies); //部门
		table.append(html_infoCreateDate);//派发时间
		table.append(html_infoCreateName);//派发人员
		table.append( html_infoPlace);//故障发生地
		table.append(html_Substation);//故障变电站
		table.append(html_Lineinfo); //故障线路
		table.append(html_Region); //故障台区
		table.append(html_Melreason); //故障原因
		table.append(html_Dispose_status); //故障处理结果
		table.append(html_Client_feedback) //用户反馈结果
		table.append( html_InfoMelfunctionType + value + html_InfoMelfunctionType2);//故障类型
	}else if(value=="QF"){
		table.append(html_Companies); //部门
		table.append(html_infoCreateDate);//派发时间
		table.append(html_infoCreateName);//派发人员
		table.append( html_infoPlace);//故障发生地
		table.append(html_Melreason); //故障原因
		table.append(html_Dispose_status); //故障处理结果
		table.append(html_Client_feedback) //用户反馈结果
		table.append( html_InfoMelfunctionType + value + html_InfoMelfunctionType2);//故障类型
	}else if(value=="KHNBGZ"){
		table.append(html_Companies); //部门
		table.append(html_infoCreateDate);//派发时间
		table.append(html_infoCreateName);//派发人员
		table.append( html_infoPlace);//故障发生地
		table.append(html_Melreason); //故障原因
		table.append(html_Dispose_status); //故障处理结果
		table.append(html_Client_feedback) //用户反馈结果
		table.append( html_InfoMelfunctionType + value + html_InfoMelfunctionType2);//故障类型
	}else if(value=="FDL"){
		table.append(html_Companies); //部门
		table.append(html_infoCreateDate);//派发时间
		table.append(html_infoCreateName);//派发人员
		table.append( html_infoPlace);//故障发生地
		table.append(html_Melreason); //故障原因
		table.append(html_Dispose_status); //故障处理结果
		table.append(html_Client_feedback) //用户反馈结果
		table.append( html_InfoMelfunctionType + value + html_InfoMelfunctionType2);//故障类型
	}else if(value=="WBX"){
		table.append(html_Companies); //部门
		table.append(html_infoCreateDate);//派发时间
		table.append(html_infoCreateName);//派发人员
		table.append( html_infoPlace);//故障发生地
		table.append(html_Melreason); //故障原因
		table.append(html_Dispose_status); //故障处理结果
		table.append(html_Client_feedback) //用户反馈结果
		table.append( html_InfoMelfunctionType + value + html_InfoMelfunctionType2);//故障类型
	}else if(value=="JLGZ"){
		table.append(html_Companies); //部门
		table.append(html_infoCreateDate);//派发时间
		table.append(html_infoCreateName);//派发人员
		table.append( html_infoPlace);//故障发生地
		table.append(html_Substation);//故障变电站
		table.append(html_Lineinfo); //故障线路
		table.append(html_Region); //故障台区
		table.append(html_Melreason); //故障原因
		table.append(html_Dispose_status); //故障处理结果
		table.append(html_Client_feedback) //用户反馈结果
		table.append( html_InfoMelfunctionType + value + html_InfoMelfunctionType2);//故障类型
	}else if(value=="WTDALXBSKH"){
		table.append(html_Companies); //部门
		table.append(html_infoCreateDate);//派发时间
		table.append(html_infoCreateName);//派发人员
		table.append( html_infoPlace);//故障发生地
		table.append(html_Melreason); //故障原因
		table.append(html_Dispose_status); //故障处理结果
		table.append(html_Client_feedback) //用户反馈结果
		table.append( html_InfoMelfunctionType + value + html_InfoMelfunctionType2);//故障类型
	}else{
		table.append(html_Companies); //部门
		table.append(html_infoCreateDate);//派发时间
		table.append(html_infoCreateName);//派发人员
		table.append( html_infoPlace);//故障发生地
		table.append(html_Substation);//故障变电站
		table.append(html_Lineinfo); //故障线路
		table.append(html_Region); //故障台区
		table.append(html_Melreason); //故障原因
		table.append(html_Dispose_status); //故障处理结果
		table.append(html_Client_feedback) //用户反馈结果
		table.append( html_InfoMelfunctionType + value + html_InfoMelfunctionType2);//故障类型
	}
}
//根据部门ID获取他的名字
function fordepart(id){
	var comPlaceName="";
	$.ajax({
		cache:false,
		async:false,
		type: 'post', // 提交方式 get/post
   		url: "volidformController.do?departDataGrid", // 需要提交的 url
   		data:{'id':id},
   		dataType:"json",
       	success: function(json){ // data 保存提交后返回的数据，一般为 json 数据
       		if(json.success){
       			comPlaceName = json.obj.comPlaceName;
       		}else{
       			return null;
       		}
       		return comPlaceName;
       	},
       	error : function(){
       		
       	}
	})
	return comPlaceName;
}


function getMyDate(str){  
    var oDate = new Date(str),  
    oYear = oDate.getFullYear(),  
    oMonth = oDate.getMonth()+1,  
    oDay = oDate.getDate(),  
    oHour = oDate.getHours(),  
    oMin = oDate.getMinutes(),  
    oSen = oDate.getSeconds(),  
    oTime = oYear +'-'+ getzf(oMonth) +'-'+ getzf(oDay) +' '+ getzf(oHour) +':'+ getzf(oMin) +':'+getzf(oSen);//最后拼接时间  
    return oTime;  
};  
//补0操作  
function getzf(num){  
    if(parseInt(num) < 10){  
        num = '0'+num;  
    }  
    return num;  
}  
